/**
 * 
 */
package com.geekteam.masterenglish.Adapter;

import android.content.Context;
import android.database.Cursor;
import android.support.v4.widget.CursorAdapter;
import android.view.View;
import android.view.ViewGroup;

import com.geekteam.masterenglish.view.ItemListView;

/**
 * @author MTROL
 *
 */
public class AlbumAdapter extends CursorAdapter{
	private static final int TYPE_MAX_COUNT = 2;
	public static final int TYPE_ALBUM = 1;
	public static final int TYPE_LESSION = 2;
	
	private int mType;
	
	public AlbumAdapter(Context context, int type) {
		super(context, null, false);
		mType = type;
	}

	@Override
	public int getViewTypeCount() {
		return TYPE_MAX_COUNT;
	}

	@Override
	public int getCount() {
		return mCursor == null ? 0 : mCursor.getCount();
	}

	@Override
	public long getItemId(int position) {
		return position;
	}
	
	@Override
	public int getItemViewType(int position) {
		return super.getItemViewType(position);
	}
	
	@Override
	public void bindView(View view, Context context, Cursor cursor) {
		ViewHolder holder = (ViewHolder) view.getTag();
		holder.mItemLessionView.updateView(cursor, mType);
	}

	@Override
	public View newView(Context context, Cursor cursor, ViewGroup parent) {
		ViewHolder holder = new ViewHolder();
		View view = new ItemListView(context);
		holder.mItemLessionView = (ItemListView) view;
		view.setTag(holder);
		return view;
	}

	public static class ViewHolder {
		public ItemListView mItemLessionView;
	}
}
